﻿using System.Collections.Generic;
using System.Linq;
using Downloader.Domain;
using Downloader.Domain.Contracts.Tasks;
using SharpArch.Domain.PersistenceSupport;

namespace Downloader.Tasks
{
    public class CategoryTasks : ICategoryTasks
    {

        private readonly IRepository<Category> categoryRepository;
       public CategoryTasks(IRepository<Category> repository)
       {
           this.categoryRepository = repository;
       }



       #region ICategoryTasks 成员

       public List<Category> GetAll()
       {
           return categoryRepository.GetAll().OrderBy(c => c.Sequence).ToList();
       }


       public Category Get(int id)
       {
           return categoryRepository.Get(id);
       }
      
       public Category CreateOrUpdate(Category category)
       {
           return categoryRepository.SaveOrUpdate(category);
       }

       public void Delete(int id)
       {
           var entity = categoryRepository.Get(id);
           this.categoryRepository.Delete(entity);
       }

       #endregion
    }
}
